package com.panopset.net.ftp;


import static com.panopset.Util.*;

import java.io.IOException;
import java.net.Socket;

/**
 * java.net.Socket wrapper.
 *
 * @author Karl Dinwiddie
 *
 */
public final class SocketWrapper {

    /**
     *
     * @param socketHost FTP server host.
     * @param socketPort FTP server port.
     */
    public SocketWrapper(final String socketHost, final int socketPort) {
        host = socketHost;
        port = socketPort;
    }

    /**
     *
     * @return Socket.
     * @throws IOException IO Exception.
     */
    public Socket getSocket() throws IOException {
        if (socket == null) {
            socket = new Socket(host, port);
        }
        return socket;
    }

    /**
     * Close the socket.
     * @throws IOException IO Exception.
     */
    public void close() throws IOException {
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                log(e);
            }
            socket = null;
        }
    }

    /**
     * Socket.
     */
    private Socket socket;

    /**
     * Host.
     */
    private final String host;

    /**
     * Port.
     */
    private final int port;

}
